import { ref, reactive } from "vue";

import { initSqliteDatabase } from "@/utils/db";

// 初始化数据库
const sqlite = await initSqliteDatabase();

// 列表数据
const listStatement = sqlite.selectStatement();
console.log('data-listStatement', listStatement.length, listStatement)
const list = ref(
  listStatement.length > 0
    ? listStatement
    : []
);
// 总数
const countStatement = sqlite.countStatement();
const count = ref(
  countStatement > 0 ? countStatement : 0
);
// 表单
const dialogVisible = ref(false);
const dialogTitle = ref("");
const formData = reactive({
  id: 0,
  name: "",
  age: 0,
});
// 搜索
const searchForm = reactive({
  name: "",
  age: "",
});

export default {
  sqlite,
  list,
  count,
  formData,
  searchForm,
  dialogVisible,
  dialogTitle,
};
